package game.joueur.jeton;

import game.joueur.Etat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class CollectionJeton {
    private List<Jeton> jetons;

    public CollectionJeton() {
        jetons = new ArrayList<Jeton>();
    }

    public int size() {
        return jetons.size();
    }

    public void add(Jeton jeton) {
        jetons.add(jeton);
    }

    public Iterator<Jeton> iterator() {
        return jetons.iterator();
    }

    public Jeton recupererJetonUtilisable() throws AucunJetonUtilisableException {
        Iterator<Jeton> jetonIterator = jetons.iterator();
        Jeton currentJeton = null;

        while (jetonIterator.hasNext()) {
            currentJeton = jetonIterator.next();
            if (currentJeton.etat() == Etat.UTILISABLE) {
                return currentJeton;
            }
        }
        throw new AucunJetonUtilisableException("Aucun jeton utilisable");
    }
}
